package zozopo.attendance;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.attendance.operations.LeaveOS;
import zozopo.attendance.operations.LeaveTB;
import zozopo.attendance.operations.OperatorAttendanceOS;
import zozopo.background.operator.operations.OperatorTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class InfoLeaveAction  extends ActionSupport implements Action,SessionAware{
	//传入参数
	private int id;
	
	//传出参数
	private String operationResult;
	private LeaveTB leave;
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		//operationResult = "已经取消。";
		return SUCCESS;
	}
	
	
	public void validate() {
		//权限处理
	
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 

		//用户权限
		
		OperatorAttendanceOS operatorOfAttendanceOS = new OperatorAttendanceOS();
		LeaveOS leaveOS = new LeaveOS(operatorOfAttendanceOS.getConn());
		
		leave = leaveOS.get(id);;
		
		if(!operatorOfAttendanceOS.isExist(operator.getId_operator())){
			operatorOfAttendanceOS.releaseConnection();
			addFieldError("errormessage","用户未加入考勤系统无法请假!请联系管理人员.!!");
			return ; 
		}
		
		
		
	
		operatorOfAttendanceOS.releaseConnection();
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getOperationResult() {
		return operationResult;
	}
	public void setOperationResult(String operationResult) {
		this.operationResult = operationResult;
	}
	public LeaveTB getLeave() {
		return leave;
	}
	public void setLeave(LeaveTB leave) {
		this.leave = leave;
	}

}
